<?php
    use User\Model\MeetingModel;
?>
<!-- page heading start-->
<div class="page-heading">
    <h3>
        自定义菜单
    </h3>

</div>
<style>
    .menu-choose{
        background-color: #ccc
    }
</style>
<!-- page heading end-->
<div class="row">
    <div class="col-sm-12">
        <section class="panel">
            <header class="panel-heading" style="height: 150px;">
                <?php
                 if(empty($list)){
                     echo '<div style="float:left;width:100px;background-color:#ccc" class="btn btn-default">菜单名称</div>';
                        echo "<div style='float:left;width:200px;'><div class='btn btn-default' data-menu-id='-1' onclick='add_menu(this)'>+</div></div>";
                    }else{
                        foreach($list as $key => $val){
                            echo "<div style='float:left;width:150px;' class='menu-div' data-menu-id='" . $val['menu_id'] . "' data-priority='" . $val['priority'] . "'>";
                            echo "<div><img src='/Public/images/arrow_left.jpg' style='width: 30px;margin-left: 20px;' onclick='change_left(this)'>";
                            echo "<img src='/Public/images/arrow_right.jpg' style='width: 30px;margin-left: 50px;' onclick='change_right(this)'></div>";
                            echo "<div style='width:150px;overflow:hidden;' class='btn btn-default exist-menu' data-menu-id='" . $val['menu_id'] ."'onclick='choose_menu(this)' >" . $val['name'] . "</div></div>";
                        }
                        echo "<div style='float:left;width:200px;margin-top: 30px;'><div class='btn btn-default' data-menu-id='-1' onclick='add_menu(this)'>+</div></div>";
                    }
                ?>
            </header>
            <div class="panel-body">
                <form class="form-horizontal" method="post"
                      action="<?php echo '/User/Meeting/menuUpdate';?>">
                    <input type="hidden" value="<?php echo I('get.meetId', -1, '');?>" name="meetId" id="meetId">
                    <input type="hidden" value="{$menu_id}" name="menuId" id="menuId">
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label need">菜单名称:</label>
                        <div class="col-lg-4">
                            <input type="text" class="form-control" name="name" value="" id="name" placeholder="字数不超过4个汉字或8个字母">
                        </div>
                    </div>

                    <div class="form-group" style="display: none">
                        <label class="col-sm-2 col-sm-2 control-label">背景图:</label>

                        <div class="col-sm-10">
                            <img src="" alt="" id="backurl_img" style="width: 200px;height: 200px;">
                            <input name="backurl" id="backurl" type="file">
                            <p class="help-block">图片建议大小750*1206。</p>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">banner图:</label>

                        <div class="col-sm-10">
                            <img src="" alt="" id="bannerurl_img" style="width: 200px;height: 200px;">
                            <input name="bannerurl" id="bannerurl" type="file">
                            <p class="help-block">图片建议大小750*200。</p>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label need">菜单模板:</label>

                        <div class="col-lg-4">
                            <?php foreach(MeetingModel::getMenu() as $menu_k => $menu_v){
                            echo '<input type="radio" name="type" onclick="getType(\'' . $menu_k . '\')" value="' . $menu_k . '">' . $menu_v . '&nbsp;&nbsp;&nbsp;';
                            }?>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label need">模板内容:</label>
                        <div class="col-lg-10">
                            <div id="menu_content">
                            </div>
                            <button class="btn btn-primary menu-class-0" data-toggle="modal" onclick="add_menu_content_text();">新增内容</button>
                            <textarea class="menu-class-1" id="editor-container" style="width:600px;height:300px;"></textarea>
                            <button class="btn btn-primary menu-class-2" data-toggle="modal" onclick="add_menu_content_text1()">新增内容</button>
                            <button class="btn btn-primary menu-class-3" data-toggle="modal" onclick="add_menu_content_text2()">新增内容</button>
                            <input type="text" class="form-control menu-class-4" name="link" value="" id="link" placeholder="外链地址">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-10">
                            <button class="btn btn-primary" type="submit" id="submit">提交</button>
                            <button class="btn btn-danger" id="delete" onclick="delete_menu(this)" data-menu-id="0">删除</button>
                            <button class="btn btn-default" type="button" onclick="history.back(-1);">取消</button>
                        </div>
                    </div>

                </form>
            </div>
        </section>
    </div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-keyboard="false">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <input type="hidden" value="" id="type-text-pic">
                <div><label class="need">标题：</label><input type='text' class="form-control" id="content-title"></div>
                <div><label >描述：</label><textarea class="form-control" id="text-describe0"></textarea></div>
                <div><label class="need">图片：</label><div><img src="" style="width: 200px;height: 200px;" alt=""><input type="file" id="picurl"><p class="help-block">图片建议大小165*165。</p></div></div>
                <div><label >类型：</label><input type="radio" name="has_detail" value="<?php echo MeetingModel::DETAIL_NO?>" onclick="setDetail(this.value)" >无
                    <input type="radio" name="has_detail" value="<?php echo MeetingModel::DETAIL_YES?>" onclick="setDetail(this.value)" >有详情
                    <input type="radio" name="has_detail" value="<?php echo MeetingModel::DETAIL_LINK?>" onclick="setDetail(this.value)" >外链
                <div id="person_detail"><textarea id="editor-container1" style="width:400px;height:200px;"></textarea></div></div>

                <div id="detail_link">链接地址：<input type='text' class="form-control" id="content-link"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="type_text_pic()">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true" data-keyboard="false">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <input type="hidden" value="" id="type-text-text">
                <div><label >类型：</label>
                    <input type="radio" name="text_main" value="<?php echo MeetingModel::TEXT_SINGLE?>" onclick="setTexttype(this.value)" >单层
                    <input type="radio" name="text_main" value="<?php echo MeetingModel::TEXT_MAIN?>" onclick="setTexttype(this.value)" >双层-主
                    <input type="radio" name="text_main" value="<?php echo MeetingModel::TEXT_UNMAIN?>" onclick="setTexttype(this.value)" >双层-副
                </div>
                <div>文字：<input type='text' class="form-control" id="text-text"></div>
                <div>描述：<textarea class="form-control" id="text-describe"></textarea></div>
                <div>链接地址：<input type='text' class="form-control" id="text-link"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="type_text_text()">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true" data-keyboard="false">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <input type="hidden" value="" id="type-pic">
                <img src="" alt="" id="menu_img" style="width: 200px;height: 200px;">
                <input name="menu_img_url" id="menu_img_url" type="file">
                <p class="help-block">建议图片宽度为750px，单张图片时高度为1156px。</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="type_pic()">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<script type="text/javascript" charset="utf-8" src="/Public/js/common/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/Public/js/common/ueditor.all.min.js"></script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="/Public/js/common/lang/zh-cn/zh-cn.js"></script>
<script>
    var editor = UE.getEditor('editor-container');
    var editor1 = UE.getEditor('editor-container1');
</script>
<script>
    //--图片处理--
    var backurl_data = '';
    var bannerurl_data = '';
    var picurl_data = '';
    var menuimgurl_data = '';
    $(function () {
        var backurl = document.getElementById("backurl");
        backurl.addEventListener('change', readFile, false);

        var bannerurl = document.getElementById("bannerurl");
        bannerurl.addEventListener('change', readFile1, false);

        var picurl = document.getElementById("picurl");
        picurl.addEventListener('change', readFile2, false);

        var menuimgurl = document.getElementById("menu_img_url");
        menuimgurl.addEventListener('change', readFile3, false);
    });
    function readFile() {
        var file = this.files[0];
        if (!/image\/\w+/.test(file.type)) {
            alert("请确保文件为图像类型");
            return false;
        }
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function () {
            $("#backurl_img").attr("src", this.result);
            backurl_data = this.result;
        }
    }

    function readFile1() {
        var file = this.files[0];
        if (!/image\/\w+/.test(file.type)) {
            alert("请确保文件为图像类型");
            return false;
        }
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function () {
            $("#bannerurl_img").attr("src", this.result);
            bannerurl_data = this.result;
        }
    }

    function readFile2() {
        var file = this.files[0];
        if (!/image\/\w+/.test(file.type)) {
            alert("请确保文件为图像类型");
            return false;
        }
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function () {
            $("#picurl").prev('img').attr("src", this.result);
            picurl_data = this.result;
        }
    }
    function readFile3() {
        var file = this.files[0];
        if (!/image\/\w+/.test(file.type)) {
            alert("请确保文件为图像类型");
            return false;
        }
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function () {
            $("#menu_img").attr("src", this.result);
            menuimgurl_data = this.result;
        }
    }

    $(".need").each(function () {
        $(this).prepend("<span style='color:red'>*</span>");
    });
    var type = 0;
    function getType(val) {
        type = val;
        show_menu_content($("#menuId").val());
    }
    $("#submit").click(function () {
        content = editor.getContent();
        var data = {
            meet_id: $("#meetId").val(),
            menuId: $("#menuId").val(),
            name: $("#name").val(),
            backurl: backurl_data,
            bannerurl: bannerurl_data,
            type: type,
            link: $("#link").val(),
            content: content,
            picurl: menuimgurl_data
        };
        var url = $("form").attr("action");
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: data,
            url: url,
            success: function (res) {
                if (res.code == 1) {
                    alert("提交成功");
                } else if(res.code == 2){
                    alert("提交成功");
                    window.location.href = '/User/meeting/menu?meetId=' + meetId + '&menu_id=' + res.menu_id;
                } else{
                    alert(res.msg);
                }
            }
        });
        return false;
    });
    var meetId = <?php echo I('get.meetId', -1, '');?>;
    var menuId = {$menu_id};
    getAjaxMenu();
    function getAjaxMenu(){
        backurl_data = '';
        bannerurl_data = '';
        menuimgurl_data = '';
        $.ajax({
            type:'get',
            dataType:'json',
            url:'/User/Meeting/ajaxMenu',
            data:{
                meetId:meetId,
                menuId:menuId
            },
            success:function(menu_choose){
                $("#menuId").val(menu_choose['menu_id']);
                $("#name").val(menu_choose['name']);
                if( menu_choose['backurl'] ){
                    $("#backurl_img").attr('src', menu_choose['backurl']);
                }else{
                    $("#backurl_img").attr('src', '');
                }
                if( menu_choose['bannerurl'] ){
                    $("#bannerurl_img").attr('src', menu_choose['bannerurl']);
                }else{
                    $("#bannerurl_img").attr('src', '');
                }
                $("input[name='type']:checked").removeAttr('checked');
                var item = "input[name='type']:radio[value=" + menu_choose['type'] + "]";
                $(item).prop('checked','true');
                type = menu_choose['type'];
                if(type == 4){
                    if(menu_choose['link']){
                        $("#link").val(menu_choose['link']);
                    }else{
                        $("#link").val('');
                    }
                }
                show_menu_content(menu_choose['menu_id'], menu_choose);
                $("#delete").attr("data-menu-id", menu_choose['menu_id']);
            }
        });
    };
    function show_menu_content(menu,menu_choose){
        $("#menu_content").html('');
        switch(type){
            case "0":
                $(".menu-class-0").css('display', 'block');
                $("#editor-container").css('display', 'none');
                $(".menu-class-2").css('display', 'none');
                $(".menu-class-3").css('display', 'none');
                $(".menu-class-4").css('display', 'none');
                $.ajax({
                    type: 'get',
                    dataType: 'json',
                    url: '/User/Meeting/getMenuContent',
                    data:{
                        menuId: $("#menuId").val(),
                        type: type
                    },
                    success:function(res){
                        var table = "<table class='table menu-class-0'><tr><th class='col-lg-3'>标题</th><th class='col-lg-3'>描述</th><th class='col-lg-3'>图片</th>";
                        table += "<th class='col-lg-3'>优先级</th><th class='col-sm-8'>操作</th></tr>";
                        for(var i=0; i < res['content'].length; i++){
                            table += "<tr class='content' data-content-id='" + res['content'][i]['content_id'] + "' data-menu-id='" + res['content'][i]['menu_id'];
                            table += "' data-type='" + res['content'][i]['type'] + "''";
                            table += "><td>" + res['content'][i]['title'] + "</td><td>" + res['content'][i]['describe'] + "</td><td><img style='width: 150px;' src='" + res['content'][i]['picurl'] + "' alt=''></td>";
                                table += "<td><img src='/Public/images/arrow_up.png' style='width: 50px;' onclick='change_up(this)'><img src='/Public/images/arrow_down.png' style='margin-left:30px;width: 50px;' onclick='change_down(this)'></td><td>";
                                table += "<button class='btn btn-primary' onclick='return edit_type_text_pic(" + res['content'][i]['content_id'] +");'>编辑</button></br><button class='btn btn-danger' style='margin-top: 10px;' onclick='return delete_menu_content(this)'>删除</button>";
                                table += "</td></tr>";
                            }
                            table += "</table>";
                            $("#menu_content").html(table);
                        }
                    });
                break;
            case "1":
                $(".menu-class-0").css('display', 'none');
                $("#editor-container").css('display', 'block');
                setTimeout(function(){if(menu_choose && menu_choose['content']){
                            editor.setContent(menu_choose['content']);
                    }else{
                        editor.setContent('');
                    }},1000);
                $(".menu-class-2").css('display', 'none');
                $(".menu-class-3").css('display', 'none');
                $(".menu-class-4").css('display', 'none');
                break;
            case "2":
                $(".menu-class-0").css('display', 'none');
                $("#editor-container").css('display', 'none');
                $(".menu-class-2").css('display', 'block');
                $(".menu-class-3").css('display', 'none');
                $(".menu-class-4").css('display', 'none');
                $.ajax({
                    type: 'get',
                    dataType: 'json',
                    url: '/User/Meeting/getMenuContent',
                    data:{
                        menuId: $("#menuId").val(),
                        type: type
                    },
                    success:function(res){
                        var table = "<table class='table menu-class-0'><tr><th class='col-lg-2'>标题</th><th class='col-lg-3'>描述</th>";
                        table += "<th class='col-lg-2'>优先级</th><th class='col-sm-8'>操作</th></tr>";
                        for(var i=0; i < res['content'].length; i++){
                            table += "<tr class='content' data-content-id='" + res['content'][i]['content_id'] + "' data-menu-id='" + res['content'][i]['menu_id'];
                            table += "' data-type='" + res['content'][i]['type'] + "''";
                            table += "><td>" + res['content'][i]['title'] + "</td><td>" + res['content'][i]['content'] + "</td>";
                            table += "<td><img src='/Public/images/arrow_up.png' style='width: 50px;' onclick='change_up(this)'><img src='/Public/images/arrow_down.png' style='margin-left:30px;width: 50px;' onclick='change_down(this)'></td><td>";
                            table += "<button class='btn btn-primary' onclick='return edit_type_text_text(" + res['content'][i]['content_id'] + ");'>编辑</button><button class='btn btn-danger' style='margin-left: 30px;' onclick='return delete_menu_content(this)'>删除</button>";
                            table += "</td></tr>";
                        }
                        table += "</table>";
                        $("#menu_content").html(table);
                    }
                });
                break;
            case "3":
                $(".menu-class-0").css('display', 'none');
                $("#editor-container").css('display', 'none');
                $(".menu-class-2").css('display', 'none');
                $(".menu-class-3").css('display', 'block');
                $(".menu-class-4").css('display', 'none');
                $.ajax({
                    type: 'get',
                    dataType: 'json',
                    url: '/User/Meeting/getMenuContent',
                    data:{
                        menuId: $("#menuId").val(),
                        type: type
                    },
                    success:function(res){
                        var table = "<table class='table menu-class-0'><tr><th class='col-lg-2'>图片</th>";
                        table += "<th class='col-lg-2'>优先级</th><th class='col-sm-8'>操作</th></tr>";
                        for(var i=0; i < res['content'].length; i++){
                            table += "<tr class='content' data-content-id='" + res['content'][i]['content_id'] + "' data-menu-id='" + res['content'][i]['menu_id'];
                            table += "' data-type='" + res['content'][i]['type'] + "''";
                            table += "><td><img style='width:100px;height:100px;' alt='' src='" + res['content'][i]['picurl'] + "'></td>";
                            table += "<td><img src='/Public/images/arrow_up.png' style='width: 50px;' onclick='change_up(this)'><img src='/Public/images/arrow_down.png' style='margin-left:30px;width: 50px;' onclick='change_down(this)'></td><td>";
                            table += "<button class='btn btn-primary' onclick='return edit_type_pic(" + res['content'][i]['content_id'] + ");'>编辑</button><button class='btn btn-danger' style='margin-left: 30px;' onclick='return delete_menu_content(this)'>删除</button>";
                            table += "</td></tr>";
                        }
                        table += "</table>";
                        $("#menu_content").html(table);
                    }
                });
                break;
            case "4":
                $(".menu-class-0").css('display', 'none');
                $("#editor-container").css('display', 'none');
                $(".menu-class-2").css('display', 'none');
                $(".menu-class-3").css('display', 'none');
                $(".menu-class-4").css('display', 'block');
                if(menu_choose && menu_choose['link']){
                    $("#link").val(menu_choose['link']);
                }else{
                    $("#link").val('');
                }
                break;
            default:
                $(".menu-class-0").css('display', 'none');
                $("#editor-container").css('display', 'none');
                $(".menu-class-2").css('display', 'none');
                $(".menu-class-3").css('display', 'none');
                $(".menu-class-4").css('display', 'none');
                break;
        }
    }
    $('.exist-menu').each(function(i){
        if($(this).attr('data-menu-id') == menuId){
            $(this).addClass('menu-choose');
        }
    });
    function choose_menu(menu){
        $('.menu-choose').removeClass('menu-choose');
        $(menu).addClass('menu-choose');
        menuId = $(menu).attr("data-menu-id");
        editor.setContent('');
        getAjaxMenu();
    }
    function add_menu(menu){
        $(menu).text("菜单名称");
        menuId = 0;
        choose_menu(menu);
    }
    function delete_menu(delete_menu){
        var delete_menu_id = $(delete_menu).attr("data-menu-id");
        if(confirm("确定删除？")){
            $.ajax({
                type: 'get',
                dataType:'json',
                url:'/User/Meeting/menuDelete',
                data:{
                    menuId:delete_menu_id
                },
                success:function(res){
                    window.location.reload();
                }
            });
        }
        return false;
    }
    function delete_menu_content(delete_content){
        var $content = $(delete_content).closest("tr");
        if(confirm("确定删除？")){
            $.ajax({
                type: 'get',
                dataType:'json',
                url:'/User/Meeting/menuContentDelete',
                data:{
                    contentId:$content.attr("data-content-id")
                },
                success:function(res){
                    $content.remove();
                }
            });
        }
        return false;
    }
    function change_right(menu){
        var $menu_div_ori = $(menu).closest(".menu-div");
        var $menu_div_des = $menu_div_ori.next(".menu-div");
        if($menu_div_des){
            $menu_div_ori.insertAfter($menu_div_des);
            var change_menu_id = $menu_div_ori.attr("data-menu-id");
            $.ajax({
                type: 'get',
                dataType:'json',
                url:'/User/Meeting/menuPriorityInc',
                data:{
                    meetId:meetId,
                    menuId:change_menu_id
                },
                success:function(res){

                }
            });
        }
    }
    function change_left(menu){
        var $menu_div_ori = $(menu).closest(".menu-div");
        var $menu_div_des = $menu_div_ori.prev(".menu-div");
        if($menu_div_des){
            $menu_div_des.insertAfter($menu_div_ori);
            var change_menu_id = $menu_div_ori.attr("data-menu-id");
            $.ajax({
                type: 'get',
                dataType:'json',
                url:'/User/Meeting/menuPriorityDec',
                data:{
                    meetId:meetId,
                    menuId:change_menu_id
                },
                success:function(res){

                }
            });
        }
    }
    function change_down(content){
        var $content_tr_ori = $(content).closest(".content");
        var $content_tr_des = $content_tr_ori.next(".content");
        if($content_tr_des){
            $content_tr_ori.insertAfter($content_tr_des);
            var change_menu_id = $content_tr_ori.attr("data-menu-id");
            var change_type = $content_tr_ori.attr("data-type");
            var change_content_id = $content_tr_ori.attr("data-content-id");
            $.ajax({
                type: 'get',
                dataType:'json',
                url:'/User/Meeting/menuContentPriorityInc',
                data:{
                    contentId:change_content_id,
                    type: change_type,
                    menuId:change_menu_id
                },
                success:function(res){

                }
            });
        }
    }
    function change_up(content){
        var $content_tr_ori = $(content).closest(".content");
        var $content_tr_des = $content_tr_ori.prev(".content");
        if($content_tr_des){
            $content_tr_des.insertAfter($content_tr_ori);
            var change_menu_id = $content_tr_ori.attr("data-menu-id");
            var change_type = $content_tr_ori.attr("data-type");
            var change_content_id = $content_tr_ori.attr("data-content-id");
            $.ajax({
                type: 'get',
                dataType:'json',
                url:'/User/Meeting/menuContentPriorityDec',
                data:{
                    contentId:change_content_id,
                    type: change_type,
                    menuId:change_menu_id
                },
                success:function(res){

                }
            });
        }
    }
    function add_menu_content_text(){
        if(!$("#menuId").val()){
            alert("请提交菜单后再新增模板内容！");
            return false;
        }
        $("#myModal").modal("show");
    }
    function add_menu_content_text1(){
        if(!$("#menuId").val()){
            alert("请提交菜单后再新增模板内容！");
            return false;
        }
        $("#myModal1").modal("show");
    }
    function add_menu_content_text2(){
        if(!$("#menuId").val()){
            alert("请提交菜单后再新增模板内容！");
            return false;
        }
        $("#myModal2").modal("show");
    }
    function edit_type_text_pic(content_id){
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: '/User/Meeting/getMenuContentByid',
            data:{
                contentId: content_id
            },
            success:function(res){
                $("#type-text-pic").val(res['content_id']);
                $("#content-title").val(res['title']);
                $("#content-link").val(res['link']);
                $("#text-describe0").val(res['describe']);
                $("#picurl").prev('img').attr("src", res['picurl']);
                if(res['link'] != ''){
                    setDetail(2);
                }
                setTimeout(function(){if(res['content'] != ''){
                    editor1.setContent(res['content']);
                    setDetail(1);
                }else{
                    setDetail(0);
                }},1000);
            }
        });
        $("#myModal").modal("show");
        return false;
    }
    function edit_type_text_text(content_id){
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: '/User/Meeting/getMenuContentByid',
            data:{
                contentId: content_id
            },
            success:function(res){
                $("#type-text-text").val(res['content_id']);
                $("#text-text").val(res['title']);
                $("#text-describe").val(res['content']);
                setTexttype(res['describe']);
                $("#text-link").val(res['link']);
            }
        });
        $("#myModal1").modal("show");
        return false;
    }
    function edit_type_pic(content_id){
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: '/User/Meeting/getMenuContentByid',
            data:{
                contentId: content_id
            },
            success:function(res){
                $("#type-pic").val(res['content_id']);
                $("#menu_img").attr("src", res['picurl']);
            }
        });
        $("#myModal2").modal("show");
        return false;
    }
    function type_text_pic(){
        if($("#menuId").val()){
            if(($("#content-title").val() == '') || (picurl_data == '' && ($("#picurl").prev('img').attr("src") == ""))){
                alert("请添加标题/图片");
                return false;
            }
            $.ajax({
                type: 'post',
                dataType:'json',
                url: '/User/Meeting/menuContentUpdate',
                data:{
                    menu_id: $("#menuId").val(),
                    type: 0,
                    title: $("#content-title").val(),
                    describe: $("#text-describe0").val(),
                    content:editor1.getContent(),
                    picurl: picurl_data,
                    contentId: $("#type-text-pic").val(),
                    link: $("#content-link").val()
                },
                success:function(res){
                    show_menu_content();
                }
            });
            $("#myModal").modal('hide');
        }
    }
    function type_text_text(){
        if($("#menuId").val()){
            $.ajax({
                type: 'post',
                dataType:'json',
                url: '/User/Meeting/menuContentUpdate',
                data:{
                    menu_id: $("#menuId").val(),
                    type: 2,
                    contentId: $("#type-text-text").val(),
                    title: $("#text-text").val(),
                    content: $("#text-describe").val(),
                    describe: $("input[name='text_main']:checked").val(),
                    link: $("#text-link").val()
                },
                success:function(res){
                    show_menu_content();
                }
            });
            $("#myModal1").modal('hide');
        }
    }
    function type_pic(){
        if($("#menuId").val()){
            $.ajax({
                type: 'post',
                dataType:'json',
                url: '/User/Meeting/menuContentUpdate',
                data:{
                    menu_id: $("#menuId").val(),
                    type: 3,
                    contentId: $("#type-pic").val(),
                    picurl: menuimgurl_data
                },
                success:function(res){
                    show_menu_content();
                }
            });
            $("#myModal2").modal('hide');
        }
    }
    $("#myModal").on('hidden.bs.modal', function(){
        picurl_data = '';
        $("#content-title").val('');
        $("#type-text-pic").val('');
        $("#content-link").val('');
        $("#text-describe0").val('');
        $("#picurl").prev('img').attr("src", '');
        $("#picurl").val('');
        setTimeout(function(){
            setDetail(0);
        }, 1000);
    });
    $("#myModal1").on('hidden.bs.modal', function(){
        $("#type-text-text").val('');
        $("#text-text").val('');
        $("#text-describe").val('');
        $("#text-describe").parent().css("display", "block");
        setTexttype(0);
        $("#text-link").val('');
    });

    $("#myModal2").on('hidden.bs.modal', function(){
        menuimgurl_data = '';
        $("#type-pic").val('');
        $("#menu_img").attr("src", "");
        $("#menu_img_url").val('');
    });

    var need_detail = 0;
    setTimeout(function(){
        setDetail(need_detail);
    }, 1000);
    function setDetail(val){
        need_detail = val;
        if(val == 0){
            $("#person_detail").hide();
            $("#content-link").val("");
            $("#detail_link").css("display", "none");
            editor1.setContent("");
            $("input:radio[name='has_detail']").eq(0).prop("checked",'checked');
            $("input:radio[name='has_detail']").eq(1).prop("checked",false);
            $("input:radio[name='has_detail']").eq(2).prop("checked",false);
        }else if(val == 1){
            $("#person_detail").show();
            $("#content-link").val("");
            $("#detail_link").css("display", "none");
            $("input:radio[name='has_detail']").eq(0).prop("checked",false);
            $("input:radio[name='has_detail']").eq(1).prop("checked",'checked');
            $("input:radio[name='has_detail']").eq(2).prop("checked",false);
        }else{
            editor1.setContent("");
            $("#detail_link").css("display", "block");
            $("input:radio[name='has_detail']").eq(0).prop("checked",false);
            $("input:radio[name='has_detail']").eq(1).prop("checked",false);
            $("input:radio[name='has_detail']").eq(2).prop("checked",'checked');
        }
    }
    function setTexttype(val) {
        if(val == 0){
            //-----
            $("input:radio[name='text_main']").eq(0).prop("checked",'checked');
            $("input:radio[name='text_main']").eq(1).prop("checked",false);
            $("input:radio[name='text_main']").eq(2).prop("checked",false);
        }else if(val == 1){
            $("input:radio[name='text_main']").eq(0).prop("checked", false);
            $("input:radio[name='text_main']").eq(1).prop("checked",'checked');
            $("input:radio[name='text_main']").eq(2).prop("checked",false);
            $("#text-describe").parent().css("display", "none");
        }else if(val == 2){
            //-----
            $("input:radio[name='text_main']").eq(0).prop("checked", false);
            $("input:radio[name='text_main']").eq(1).prop("checked", false);
            $("input:radio[name='text_main']").eq(2).prop("checked",'checked');
        }
    }
</script>